package com.zl.controller;

import com.zl.component.UserComponent;
import com.zl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

//得到UserService三部曲
//1.最早:new UserService
//2.Spring:1.得到Spring对象 2.使用getBean读取到UserService
//3.更简单的读取方式:对象注入(属性注入,Setter注入,构造方法注入)
@Controller
public class UserController {

    //1.属性注入(Field Injection)
//    @Autowired//自动装配
//    private UserService userService;


    //2.setter注入
//    private UserService userService;
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }
    //3.构造方法注入(Constructor Injection)
    private UserService userService;
    //private UserComponent userComponent;
    @Autowired
    public UserController(UserService userService, UserComponent userComponent){
        this.userService=userService;
        //this.userComponent=userComponent;
    }


//    public UserController(UserService userService,Integer age){
//        this.userService=userServ ice;
//    }

    public void doUseController(){
        System.out.println("doUseController");
        userService.doService();
        //userComponent.doUserComponent();

    }
}
